{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e1157310",
   "metadata": {},
   "source": [
    "---\n",
    "* 日期：2022-10-26\\week10（周三）\n",
    "* 课程：python\n",
    "* 记录人：zeng\n",
    "---\n",
    "\n",
    "\n",
    "# *本周学习方法*\n",
    "> 1. \n",
    "> 2. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87c07dfc",
   "metadata": {},
   "source": [
    "## Directory 课后习题 购物车程序项目：\n",
    "> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户\n",
    "> 2.让用户输入商品编号进行商品购买\n",
    "> 3. 用户选择商品后，检查用户余额是否够，若够则直接购买，否则提醒用户充值\n",
    "> 4. 用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ddf74a56",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\n",
    "    [\"iphone 14 promax 暗夜紫\",9999]\n",
    "    [\"天官赐福周边\",66]\n",
    "    [\"诺基亚8+256G\",2999]\n",
    "    [\"魔道祖师周边\",66]\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35feac5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "Ailpay = input(\"请输入余额：\")\n",
    "print"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2eae7856",
   "metadata": {},
   "outputs": [],
   "source": [
    "user_choice = inout(\"请输入商品编号：\")\n",
    "# 0,1,2,3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "909ffa2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "if 钱够， Ailpay - 商品价格\n",
    "else print(\"您的余额不足，请更换支付方式\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "eaa305b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：666\n",
      "\n"
     ]
    }
   ],
   "source": [
    "Ailpay = int(input(\"请输入余额：\"))\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "6d73766b",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_9484/1812738857.py, line 15)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\樂\\AppData\\Local\\Temp/ipykernel_9484/1812738857.py\"\u001b[1;36m, line \u001b[1;32m15\u001b[0m\n\u001b[1;33m    print(user_chioce[])\u001b[0m\n\u001b[1;37m                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"电动车\",3500],\n",
    "    [\"天官赐福周边\",66],\n",
    "    [\"诺基亚8+256G\",2999],\n",
    "    [\"魔道祖师周边\",66],\n",
    "]\n",
    "shopping_card =[]\n",
    "Ailpay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"product_list\")\n",
    "    for i in range(4):\n",
    "        print(product_list[i])\n",
    "    Ailpay = int(input(\"请输入商品编号：\"))\n",
    "    print(user_chioce[])\n",
    "    if Ailpay >= user_choice:\n",
    "        print(\"购买成功！\")\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "77df4943",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2beca279",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (Temp/ipykernel_23208/2814724269.py, line 20)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\樂\\AppData\\Local\\Temp/ipykernel_23208/2814724269.py\"\u001b[1;36m, line \u001b[1;32m20\u001b[0m\n\u001b[1;33m    print(\"商品购买成功，您的余额还有%s元\"%(Alipay))\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"电动车\",3500],\n",
    "    [\"天官赐福周边\",66],\n",
    "    [\"诺基亚8+256G\",2999],\n",
    "    [\"魔道祖师周边\",66]\n",
    "]\n",
    "\n",
    "shopping_car =[]\n",
    "Ailpay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"————商品列表————\")\n",
    "    for i in range(4):\n",
    "        print(\"商品编号：\"+str(i),product_list[i])\n",
    "    user_chioce = input(\"请输入商品编号：\")\n",
    "    if user_chioce.isdigit():\n",
    "        # 判断钱够不够,商品是谁？ ==>product_list[user_chioce][1]\n",
    "        if Ailpay >= product_list[int(user_chioce)][1]:\n",
    "            Ailpay = Ailpay - product_list[int(user_chioce)][1] #买完剩余的钱\n",
    "            shopping_car.append(product_list[int(user_chioce)])\n",
    "             print(\"商品购买成功，您的余额还有%s元\"%(Alipay))\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式\")\n",
    "        # 情景2 用户输入“q”退出购买\n",
    "    elif user_chioce == \"Q\":\n",
    "        print(\"您的购物车：\",shopping_car)\n",
    "        print(\"您的余额还有：\"，Ailpay)\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4202711",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.运行程序后，让用户输入支付宝余额√，然后打印我们的商品列表给用户。√\n",
    "\n",
    "product_list = [\n",
    "    [\"柠檬水\",6],\n",
    "    [\"蜜桃四季春\",10],\n",
    "    [\"芒果奶盖\",12],\n",
    "    [\"葡萄啵啵奶茶\",8],\n",
    "]\n",
    "shopping_car = []\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"---------商品列表--------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号:\",i,product_list[i][0],str(product_list[i][1])+\"元\")  # 格式化输出\n",
    "    # 2.让用户输入商品编号进行商品的购买（列表）。：直接用商品列表的index作为商品标号\n",
    "    user_choice = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号    \n",
    "    if user_choice.isdigit():\n",
    "       # 情景一：余额大于商品价格\n",
    "      if  Alipay >= product_list[int(user_choice)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)][1])\n",
    "            print(\"商品购买成功，正在制作中...您的余额还有%s元\"%(Alipay))\n",
    "     # 情景二：余额小于商品价格\n",
    "      else:\n",
    "        print(\"您的余额不足，请更换支付方式~~~~\")\n",
    "    #  情景2：用户输入退出，结束购买\n",
    "    elif user_choice ==\"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)\n",
    "        print(\"您的余额还有%s,欢迎下次光临~~~\"%(Alipay))\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be121ad5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
